function mapedit_init(data) {
	//Create a closure just to ensure isolation;
	(function() {
		data.buttonHolder = $(data.buttonHolder);
		if (!data.buttonHolder) {
			return;
		}
		var removeButton = new Element('input', {'type': 'button', 'value': 'Poista paikka'});
		var editButton = new Element('input', {'type': 'button', 'value': 'Muuta sijaintia'});
		var assignButton = new Element('input', {'type': 'button', 'value': 'Liitä sijaintitiedot'});
		var holder = new Element('div');
		
		var updateHolder = function() {
			holder.empty();
			if (data.position_id) {
				holder.adopt(removeButton);
				holder.adopt(editButton);
			} else {
				holder.adopt(assignButton);
			}
		}
		updateHolder();
		
		var fader = new Element('div', {'class':'mapedit_fader'});
		fader.setStyle('opacity', 0.5);
		var popup = new Element('div', {'class':'mapedit_popup'});
		
		var closeDialog = function() {
			//Must cancel any active pannings
			popup.m.map.setCenter(popup.m.map.getCenter(), popup.m.map.getZoom(), false, false);
			
			popup.m.destroy();
			//PL: popup.remove(); mootools remove -> dispose since 1.2
			popup.dispose();
			
//			popup.setStyle('display','none');
			
			//Enable popups previously disabled
			$$('select').each(function(element) {
				//element.setStyle('visibility', element.retrieve('oldVisibility'));
				element.setStyle('visibility', 'visible');
			});
			
//			popup.positionSelect.empty();
//			popup.searchField.value = '';
//			popup.osoiteField.value = '';
//			popup.positionField.value = '';
			
			//PL: 
			//fader.remove();
			fader.dispose();
//			fader.setStyle('display','none');
		}
		fader.addEvent('click', closeDialog);
		
		var geocoder = new GClientGeocoder();
		geocoder.setBaseCountryCode('fi');
		var geocodeTimeout;
		var geocodeSearch = function(button, goto, timeout, field) {
			$clear(timeout);
			var search = field.value ;
			if (!search || search.length < 3) {
				return;
			}

			geocoder.getLocations(search + ", Helsinki", function(data) {
				if (data.Placemark && data.Placemark.length) {
					var place = data.Placemark[0];
					if (place.AddressDetails.Country.CountryNameCode != 'FI') {
						return;
					}
					var accuracy = place.AddressDetails.Accuracy;
					var address = search;
					if (accuracy >= 6 ){
						address = place.address;
						address = address.match('^[^,]*');
					}
					if (accuracy < 4) {
						return;
					}
					var lon = place.Point.coordinates[0];
					var lat = place.Point.coordinates[1];
					
					button.setStyle('display', 'inline');
					button.point = new GLatLng(lat, lon);
					button.address = address;
					if (goto) {
						(gotoGeocode.bind(button))();
					}
				}
			});
		}
		
		var gotoGeocode = function() {
			//The button to get the point from is bound to this
			var point = this.point;
			popup.m.setSelectedMarker(point.lng(), point.lat(), true);
			if (this.address && !popup.osoiteField.entered) {
				popup.osoiteField.value = this.address;
			}
		}
		
		var namePositionSorter = function(p1, p2) {
			return p1.dpposition_name > p2.dpposition_name;
		}
		
		
		var osoiteTimeout;
		var osoiteTrigger = function() {
			if (osoiteTimeout) {
				$clear(osoiteTimeout);
			}
			popup.osoiteGoto.setStyle('display', 'none');
			osoiteTimeout = geocodeSearch.delay(1000, null, [popup.osoiteGoto, false, osoiteTimeout, popup.osoiteField]);
		}
		
		var searchTrigger = function() {
			if (geocodeTimeout) {
				$clear(geocodeTimeout);
			}
			popup.searchGoto.setStyle('display', 'none');
			geocodeTimeout = geocodeSearch.delay(1000, null, [popup.searchGoto, false, geocodeTimeout, popup.searchField]);
			
			var search = popup.searchField.value;
			if (search) {
				var startMatch = [];
				var otherMatch = [];
				var startPattern = new RegExp('^' + search.escapeRegExp(),'i');
				var otherPattern = new RegExp(search.escapeRegExp(),'i');
				popup.positions.each(function(element) {
					var hit = false;
					if (startPattern.test(element.dpposition_name)) {
						startMatch.push(element);
						hit = true;
					} else if (otherPattern.test(element.dpposition_name) || otherPattern.test(element.dpposition_street)) {
						otherMatch.push(element);
						hit = true;
					}
					var newMarker = null;
					if (element.marker) {
						if (hit && !element.marker.highlight) {
							newMarker = createMarker(element, true);
						} else if (!hit && element.marker.highlight) {
							newMarker = createMarker(element, false);
						}
						if (newMarker) {
							popup.m.markers.removeMarker(element.marker);
							element.marker.destroy();
							element.marker = newMarker;
							popup.m.markers.addMarker(newMarker);
						}
					}
				});
				startMatch.sort(namePositionSorter);
				otherMatch.sort(namePositionSorter);
				setSelectElements(startMatch.concat(otherMatch));
				
			} else {
				setSelectElements(null);
				popup.positions.each(function(element) {
					if (element.marker && element.marker.highlight) {
						popup.m.markers.removeMarker(element.marker);
						element.marker.destroy();
						element.marker = createMarker(element, false);
						popup.m.markers.addMarker(element.marker);
					}
				});
			}
			if (popup.m.selectedMarker) {
				//Must add the marker again to make ensure it's on top
				popup.m.markers.removeMarker(popup.m.selectedMarker);
				popup.m.markers.addMarker(popup.m.selectedMarker);
			}
			
		}
		
		function sortLocations() {
			if (popup.m.selectedMarker) {
				var markerLon = popup.m.selectedMarker.realLon;
				var markerLat = popup.m.selectedMarker.realLat;
			} else {
				var center = popup.m.map.getCenter();
				var markerLon = center.lon;
				var markerLat = center.lat;
			}
			popup.positions.sort(function(e1, e2) {
				var d1 = Math.sqrt((e1.dpposition_lon - markerLon)*(e1.dpposition_lon - markerLon)
					+ (e1.dpposition_lat - markerLat)*(e1.dpposition_lat - markerLat));
				var d2 = Math.sqrt((e2.dpposition_lon - markerLon)*(e2.dpposition_lon - markerLon)
					+ (e2.dpposition_lat - markerLat)*(e2.dpposition_lat - markerLat));
				return d1 - d2;
			});
			
			popup.positions.each(function(element, index) {
				if (index <= 50) {
					if (!element.marker) {
						element.marker = createMarker(element);
						popup.m.markers.addMarker(element.marker);
					}
				} else {
					if (element.marker) {
						popup.m.markers.removeMarker(element.marker);
						element.marker.destroy();
						element.marker = null;
					}
				}
				
			});
		}
		
		OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {                
			defaultHandlerOptions: {
				'single': true,
				'double': false,
				'pixelTolerance': 0,
				'stopSingle': false,
				'stopDouble': false
			},
			
			initialize: function(options) {
				this.handlerOptions = OpenLayers.Util.extend(
					{}, this.defaultHandlerOptions
				);
				OpenLayers.Control.prototype.initialize.apply(
					this, arguments
				); 
				this.handler = new OpenLayers.Handler.Click(
					this, {
						'click': this.trigger
					}, this.handlerOptions
				);
			}, 
			
			trigger: function(e) {
				popup.osoiteField.blur();
				if (!popup.osoiteField.value) {
					popup.osoiteField.entered = false;
				}
				if (shownBubble) {
					showBubble(null, false);
					return;
				}
				var lonlat = popup.m.map.getLonLatFromViewPortPx(e.xy);
				
				//Must turn into google coordinates of we get the coordinates from a helsinki map
				if (popup.m.mapType == OLDPPositionMap.MAP_TYPE_HEL) {
					var c = popup.m.metersToDegrees(lonlat.lat, lonlat.lon);
					lonlat.lon = c[0];
					lonlat.lat = c[1];
				}
				
				popup.m.setSelectedMarker(lonlat.lon, lonlat.lat, false);
				sortLocations();
				
				if (!popup.osoiteField.entered) {
					geocoder.getLocations(new GLatLng(lonlat.lat, lonlat.lon), function(data) {
						if (data.Placemark && data.Placemark.length) {
							var place = data.Placemark[0];
							var accuracy = place.AddressDetails.Accuracy;
							if (accuracy >= 6 ){
								var address = place.address;
								address = address.match('^[^,]*');
								popup.osoiteField.value = address;
							} else {
								popup.osoiteField.value = '';
							}
						} else {
							console.log(data);
						}
					});
				}
				//Rebuld list of closest
				if (!popup.searchField.value) {
					setSelectElements(null);
				}
			}
		});		
		
		var shownBubble;
		var showBubble = function(place, jump) {
			if (shownBubble) {
				popup.m.map.removePopup(shownBubble);
				popup.selectDisabler.setStyle('display', 'none');
				popup.positionSelect.getElements('option').selected = false;
				//popup.positionSelect.selectedIndex = -1;
				shownBubble = null;
				return;
			}
			if (place) {
				if (!place.marker) {
					place.marker = createMarker(place);
					popup.m.markers.addMarker(place.marker);
				}
				var marker = place.marker;
				var content = '<div class="bubbleContent"><div class="name">';
				content += place.dpposition_name;
				content += '</div>';
				if (place.dpposition_street) {
					content += '<div class="street">' + place.dpposition_street + '</div>';
				}
				content += '<button onclick="window.usePosition('+place.dpposition_id+')">Käytä&nbsp;tätä</button>';
				content += '</div>';
				var bubble = new OpenLayers.Popup.FramedCloud(null,
					marker.lonlat,
					new OpenLayers.Size(200, 100),
					content,
					marker.icon,
					true,
					function() {
						showBubble(null);
				});
				
				popup.selectDisabler.setStyle('display', 'block');
				bubble.maxSize = new OpenLayers.Size(200, 10000);
//				bubble.panMapIfOutOfView = false;
				bubble.fixedRelativePosition = true;
				shownBubble = bubble;
				
				if (jump) {
					popup.m.centerAt(marker.lonlat.lon, marker.lonlat.lat);
				}
				popup.m.map.addPopup(bubble);
			}
		}
		
		window.usePosition = function(position) {
			data.position_id = position;
			var name = '';
			popup.positions.each(function(element) {
				if (element.dpposition_id == position) { 
					data.position_name = element.dpposition_name;
					data.position_address = element.dpposition_street;
					data.position_zoom = element.dpposition_zoom;
					data.position_lon = element.dpposition_lon;
					data.position_lat = element.dpposition_lat;
				}
			});
			
			//updateHolder();
			data.update();
			closeDialog();
		}
		
		var setSelectElements = function(list) {
			if (!list) {
				popup.selectLabel.set('text','Lähimmät');
				list = popup.positions;
			} else {
				if (list.length) {
					popup.selectLabel.set('text','Hakutulokset');
				} else {
					popup.selectLabel.set('text','Hakutulokset - ei osumia');
				}
			}
			
			popup.positionSelect.empty();
			list.each(function(element, index) {
				var option = new Element('option', {
					'value': index
				}).set('text',element.dpposition_name);
				option.element = element;
				popup.positionSelect.adopt(option);			
			});
		}
		
		var createMarker = function(element, highlight) {
			var point = popup.m.convertPosition(element.dpposition_lon, element.dpposition_lat);
			var icon = popup.m.placeIcon;
			if (highlight) {
				icon = popup.m.hitIcon;
			}
			var marker = new OpenLayers.Marker(new OpenLayers.LonLat(point.lon,point.lat),icon.clone());
			marker.events.register('click', null, function() {
				showBubble(element, false);
			});
			marker.highlight = highlight;
			return marker;
		}
		
		var createDialog = function() {
			popup.searchField = new Element('input');
			popup.searchField.addEvent('keyup', function(event) {
				if (event.key == 'enter') {
					if (popup.searchGoto.getStyle('display') != 'none') {
						popup.searchGoto.click();
					} else {
						geocodeSearch(popup.searchGoto, true, geocodeTimeout, popup.searchField);
					}
				} else {
					searchTrigger();
				}
			});
			
			var searchBox = new Element('div', {'id':'mapSearchBox'});
			popup.searchGoto = new Element('button', {
				'styles': {
					'display': 'none'
				}
			}).set('text','Kartalla');
			//});
			popup.searchGoto.addEvent('click', gotoGeocode.bind(popup.searchGoto));

			//searchBox.adopt(new Element('label', {'for':searchBox.id}).setHTML('Hae paikka'));
			searchBox.adopt(new Element('label', {html: 'Hae paikka', 'for':searchBox.id}));
			searchBox.adopt(popup.searchField);
			searchBox.adopt(popup.searchGoto);
			
			var mapDiv = new Element('div', {'id': 'mapDiv'});
			popup.positionSelect = new Element('select', {
				'size': '12',
				'events': {
					'click': function(event) {
				
						var target = (event.target || event.srcElement);
				
						if (target.get('tag') == 'option') {
							var element = target.element;
						} else if (target == popup.positionSelect) {
							var selectedIndex = popup.positionSelect.selectedIndex;
							if (selectedIndex >= 0) {
								var option = popup.positionSelect.options[selectedIndex]
								if (option) {
									var element = option.element;
								}
							}
						}
						
						if (element) {
							showBubble(element, true);
						}
					}
				} 
			});
			popup.selectDisabler = new Element('div', {
				'class': 'selectDisabler',
				'events': {
					'mousedown': function() {
						showBubble(null);
						popup.positionSelect.focus();
					}
				}
			});
			
			popup.selectLabel = new Element('div', {'class': 'positionLabel'});
			
			var selectHolder = new Element('div', {'class': 'positionSelect'});
			selectHolder.adopt(popup.selectLabel);
			selectHolder.adopt(popup.positionSelect);
			selectHolder.adopt(popup.selectDisabler);
			
			popup.osoiteField = new Element('input', {'id':'mapOsoiteField'});
			popup.osoiteField.addEvent('keyup', function(event) {
				popup.osoiteField.entered = true;
				if (event.key == 'enter') {
					if (popup.osoiteGoto.getStyle('display') != 'none') {
						popup.osoiteGoto.click();
					} else {
						geocodeSearch(popup.osoiteGoto, true, osoiteTimeout, popup.osoiteField);
					}
				} else {
					osoiteTrigger();
				}
			});
			popup.osoiteField.addEvent('change', function() {
				if (!popup.osoiteField.value) {
					popup.osoiteField.entered = false;
				}
			});
			
			popup.osoiteGoto = new Element('button', {
				html: 'Kartalla',
				'styles': {
					'display': 'none'
				}
			//}).setHTML('Kartalla');
			});
			popup.osoiteGoto.addEvent('click', gotoGeocode.bind(popup.osoiteGoto));			
			
			var osoiteRow = new Element('div');
			//osoiteRow.adopt(new Element('label', {'for':popup.osoiteField.id}).setHTML('Osoite:'));
			osoiteRow.adopt(new Element('label', {html:'Osoite', 'for':popup.osoiteField.id}));
			osoiteRow.adopt(popup.osoiteField);
			osoiteRow.adopt(popup.osoiteGoto);
			
			popup.positionField = new Element('input', {'id':'mapPositionField'});
			var positionRow = new Element('div');
			//positionRow.adopt(new Element('label', {'for':popup.positionField.id}).setHTML('Paikan nimi:'));
			positionRow.adopt(new Element('label', {html: 'Paikan nimi', 'for':popup.positionField.id}));
			positionRow.adopt(popup.positionField);
			
			var cancelButton = new Element('button', {
				html: 'Peruuta',
				'events': {
					'click':closeDialog
				}
			//}).setHTML('Peruuta');
			});
			var saveButton = new Element('button', {
				html: 'Tallenna',
				'events': {
					'click': function() {
						if (popup.m.defaultPosition && popup.m.defaultPosition.dpposition_lat == popup.m.selectedMarker.realLat && popup.m.defaultPosition.dpposition_lon == popup.m.selectedMarker.realLon) {
							window.alert('Valitse paikka kartalla!');
							return;
						}
						var name = popup.positionField.value;
						if (!name) {
							window.alert('Syötä paikan nimi!');
							return;
						}

						//var saveRequest = new Ajax('index2.php',{
						var saveRequest = new Request({
							url: 'index2.php',
							method: 'post',
							data: {
								'option': 'com_mapedit',
								'no_html': 1,
								'task': 'create',
								'lon': popup.m.selectedMarker.realLon,
								'lat': popup.m.selectedMarker.realLat,
								'zoom': popup.m.map.getZoom(),
								'address': popup.osoiteField.value,
								'name': name
							},
							onComplete: function(id) {
								if (id) {
									data.position_id = id;
									data.position_name = popup.positionField.value;
									data.position_address = popup.osoiteField.value;
									data.position_zoom = popup.m.map.getZoom();
									data.position_lon = popup.m.selectedMarker.realLon;
									data.position_lat = popup.m.selectedMarker.realLat;
									data.update();
									updateHolder();
									closeDialog();
								} else {
									//TODO error handling? ;)
								}
							}
						});   
						//saveRequest.request();
						saveRequest.send();
					}
				}
		//	}).setHTML('Tallenna');
			});
			
			var buttonHolder = new Element('div', {'class': 'buttonHolder'});
			buttonHolder.adopt(cancelButton);
			buttonHolder.adopt(saveButton);
			
			var newHolder = new Element('div', {'class': 'newHolder'});
			//newHolder.adopt(new Element('h3').setHTML('Tee uusi paikka'));
			newHolder.adopt(new Element('h3', {html:'Tee uusi paikka'}));
			
			var _newDescr = new Element('div', {html: 'Palvelun sijainti tallentuu yhteiseen paikkatietokantaan, josta ne ovat kaikkien kaupunginosasivujen käytettävissä.', 'class':'newDescr'});
			//_newDescr.setHTML('Palvelun sijainti tallentuu yhteiseen paikkatietokantaan, josta ne ovat kaikkien kaupunginosasivujen käytettävissä.');
			newHolder.adopt(_newDescr);
			newHolder.adopt(osoiteRow);
			
			//newHolder.adopt(new Element('div', {'class': 'esim'}).setHTML('Esim. Vuotalo, Länsisatama, Kampin keskus'));
			newHolder.adopt(new Element('div', {html: 'Esim. Vuotalo, Länsisatama, Kampin keskus', 'class': 'esim'}));
			newHolder.adopt(positionRow);
			newHolder.adopt(buttonHolder);
			newHolder.adopt(new Element('br', {'style': 'clear: both'}));
			
			//popup.adopt(new Element('div', {'class': 'intro'}).setHTML('Valitse paikka aiemmin tallennetuista sijaintitiedoista, tai tee uusi'));
			//popup.adopt(new Element('div', {'class': 'esim'}).setHTML('Esim. Kampin keskus, Ruohonlahdenkatu 4...'));			
			popup.adopt(new Element('div', {html: 'Valitse paikka aiemmin tallennetuista sijaintitiedoista, tai tee uusi', 'class': 'intro'}));
			popup.adopt(new Element('div', {html: 'Esim. Kampin keskus, Ruohonlahdenkatu 4...', 'class': 'esim'}));
			popup.adopt(searchBox);
			popup.adopt(mapDiv);
			popup.adopt(selectHolder);
			popup.adopt(new Element('br', {'style': 'clear: both'}));
			popup.adopt(newHolder);
			popup.adopt(new Element('br', {'style': 'clear: both'}));
		};
		
		var openDialog = function() {
			if (popup.getChildren().length == 0) {
				createDialog();
			}
			if (data.position_name) {
				popup.positionField.value = data.position_name;
			} else if (data.getDefaultName) {
				popup.positionField.value = data.getDefaultName();
			}
			
			//Must disable any selects because of IE6
			$$('select').each(function(element) {
				//element.store('oldVisibility', element.getStyle('visibility'));
				element.setStyle('visibility', 'hidden');
			});
			
			fader.inject($(document.body), 'top');
			popup.inject($(document.body), 'top');
			fader.setStyle('height', $(document).getScrollSize().y + 100);
//			fader.setStyle('height', window.getSize().scrollSize.y + 100);
			fader.setStyle('display','block');
				
			
			//Center popup on the screen
			//var window_scroll = window.getSize().scroll;
			var window_scroll = window.getScroll();
			//var window_size = window.getSize().size;
			var window_size = window.getSize();
			//var popup_size = popup.getSize().size;
			var popup_size = popup.getSize();

			
			popup.setStyle('left', window_scroll.x + (window_size.x - popup_size.x) / 2);
			if(window.opera){
				popup.setStyle('top', window_scroll.y - (popup_size.y/2 - 100) + ((window_size.y - popup_size.y) / 2));
			}else{
				popup.setStyle('top', window_scroll.y + ((window_size.y - popup_size.y) / 2));
			}

//			alert(popup.getStyle('top'));
			
			popup.m = new OLDPPositionMap({
				divID:      "mapDiv",
				iconUrl:    "components/com_dpposition/images/needle.png",
				iconWidth:  20,
				iconHeight: 34
			});
			
			var click = new OpenLayers.Control.Click();
			popup.m.map.addControl(click);
			click.activate();
			
			var s = new OpenLayers.Size(21, 21);
			var o = new OpenLayers.Pixel(-(s.w/2), -(s.h/2));
			popup.m.placeIcon = new OpenLayers.Icon('components/com_mapedit/yellow_ball.png', s,o);			
			popup.m.hitIcon = new OpenLayers.Icon('components/com_mapedit/green_ball.png', s,o);			
			
			popup.m.map.addControl(new OpenLayers.Control.PanZoom());			
			popup.m.map.addControl(new OpenLayers.Control.Navigation());
			
			popup.m.convertPosition = function(lon, lat) {
				if( (/^\d+$/).test(lon)){
					if (this.mapType == OLDPPositionMap.MAP_TYPE_HEL) {
						return {lon: lon, lat: lat}
					} else {
						var c = this.metersToDegrees(lat, lon);
						return {lon: c[0], lat: c[1]};
					}
				}else{
					if (this.mapType == OLDPPositionMap.MAP_TYPE_HEL) {
						var c = this.degreesToMeters(lat, lon);
						return {lon: c[0], lat: c[1]};
					} else {
						return {lon: lon, lat: lat}
					}
				}
			}
			
			popup.m.setSelectedMarker = function(lon, lat, center) {
				var point = this.convertPosition(lon, lat);
				if (this.selectedMarker) {
					this.markers.removeMarker(this.selectedMarker);
					this.selectedMarker.destroy();
				}
				this.selectedMarker = new OpenLayers.Marker(new OpenLayers.LonLat(point.lon,point.lat),this.mapIcon.clone());
				this.selectedMarker.realLon = lon;
				this.selectedMarker.realLat = lat;
				this.markers.addMarker(this.selectedMarker);
				if (center) {
					this.centerAt(lon, lat);
				}
			}
			
			popup.m.centerAt = function(lon, lat, zoom) {
				var point = this.convertPosition(lon, lat);
				this.map.setCenter(new OpenLayers.LonLat(point.lon, point.lat), zoom);
			}
			var origData = data;
		//	var positionRequest = new Json.Remote('index.php?option=com_mapedit&no_html=1&task=getPosition&id='+data.position_id,{
			
			var positionRequest = new Request.JSON({url: 'index.php?option=com_mapedit&no_html=1&task=getPosition&id='+data.position_id,
				//onComplete: function(data, text) {
				onSuccess: function(data,text) {
			
					
					if (data.position) {
						var pos = data.position;
						if(!origData.position_id && origData.position_lon && origData.position_lat){
							popup.m.setSelectedMarker(origData.position_lon, origData.position_lat, true);
							popup.m.map.zoomTo(15);
						}else{
							popup.m.setSelectedMarker(pos.dpposition_lon, pos.dpposition_lat, true);
							popup.m.map.zoomTo(pos.dpposition_zoom.toInt());
						}
						
						if(!origData.position_id && origData.position_address){
							if (origData.position_address) {
								popup.osoiteField.value = origData.position_address;
							}
						}else{
							if (pos.dpposition_street) {
								popup.osoiteField.value = pos.dpposition_street;
							}
						}
						if (pos.dpposition_name) {
							popup.positionField.value = pos.dpposition_name;
						}
						if (pos.isDefault) {
							popup.m.defaultPosition = pos;
						}
					}
					
					if (data.list) {
						var list  = data.list;
						list.each(function(element, index) {
							if (!data.position.isDefault && data.position.dpposition_id == element.dpposition_id) {
								//Must add this marker manually to make the bubble behave
								element.marker = createMarker(element);
								popup.m.markers.addMarker(element.marker);
								showBubble(element, false);
//								alert('Must add this marker manually to make the bubble behave');
							}
						});
						if (popup.m.selectedMarker) {
							popup.m.markers.removeMarker(popup.m.selectedMarker);
							popup.m.markers.addMarker(popup.m.selectedMarker);
						}
						popup.positions = list;
						sortLocations();
						setSelectElements(null);
					}
					
				}
			}); 
			positionRequest.send();
			
			popup.m.map.zoomToMaxExtent = function() {
				//Zoom to central Helsinki
				var lonlat = popup.m.convertPosition(24.937505722, 60.169610135);
				this.setCenter(new OpenLayers.LonLat(lonlat.lon, lonlat.lat), OLDPPositionMap.MAP_TYPE_HEL?1:15);
			}
		}
		
		editButton.addEvent('click', openDialog);
		assignButton.addEvent('click', openDialog);
		removeButton.addEvent('click', function() {
			var locationName = data.position_name;
			if (!window.confirm('Haluatko varmasti poista tämän palvelun paikasta ' + locationName + '?')) {
				return;
			}
			data.position_id = 0;
			data.position_name = '';
			data.position_address = '';
			data.position_lon = 0;
			data.position_lat = 0;
			data.position_zoom = 0;
			data.update();
			
			updateHolder();
		});
		
		
		data.buttonHolder.adopt(holder);
	})();
}